<?php defined('SYSPATH') or die('No direct access allowed.');

class Model_Price_Channel extends ORM
{
    /**
     * @param $product_id
     * @param $type_id
     * @return array
     * 获取渠道
     */
    public static function get_ota_channel($product_id,$type_id)
    {
        $table_name = St_Functions::table_field($type_id);
        if($type_id==5){
            $supplier_id = DB::select()->from($table_name[0])->where("id={$product_id}")->execute()->get('supplierlist');
        }else{
            $supplier_id = DB::select()->from($table_name[3])->where("id={$product_id}")->execute()->get('supplierlist');
        }
        $sql = '';
        if($type_id!=2){
            $sql = 'and id!=3';
        }
        if($type_id==3){
            $sql = 'and id NOT IN(2,3)';
        }

        if(!$supplier_id){
            $channel = DB::select()->from('ota_channel')->where("id>0 {$sql}")->execute()->as_array();
            return array(
                'supplier' => false,
                'channel'  => $channel
            );
        }
        $channel_id = DB::select()->from('supplier')->where("id={$supplier_id}")->execute()->get('channel_id');
        $in_sql = $channel_id?"id IN({$channel_id}) ":'id IN(1) ';

        $channel = DB::select()->from('ota_channel')->where("{$in_sql} {$sql}")->execute()->as_array();

        return array(
            'supplier' => true,
            'channel'  => $channel
        );
    }

    /**
     * @param $type_id
     * @return array|string[][]
     * 日历显示字段
     */
    public static function calendar_config($type_id)
    {
        if($type_id==1){
            /*获取开启的人群*/
            $child_name = DB::select()->from('sysconfig')->where("varname='cfg_line_child_name'")->execute()->get('value');
            $adult_name = DB::select()->from('sysconfig')->where("varname='cfg_line_adult_name'")->execute()->get('value');
            $old_name   = DB::select()->from('sysconfig')->where("varname='cfg_line_old_name'")->execute()->get('value');
            $child_name = !empty($child_name) ? $child_name : '儿童';
            $adult_name = !empty($adult_name) ? $adult_name : '成人';
            $old_name   = !empty($old_name) ? $old_name : '老人';
            $peo_arr = array(
                1 => array(
                    'key' => 'childprice',
                    'name' => $child_name
                ),
                2 => array(
                    'key' => 'adultprice',
                    'name' => $adult_name
                ),
                3 => array(
                    'key' => 'oldprice',
                    'name' => $old_name
                ),
                4 => array(
                    'key' => 'people4_price',
                    'name' => DB::select()->from('sysconfig')->where("varname='cfg_line_people4_name'")->execute()->get('value')
                ),
                5 => array(
                    'key' => 'people5_price',
                    'name' => DB::select()->from('sysconfig')->where("varname='cfg_line_people5_name'")->execute()->get('value')
                ),
                6 => array(
                    'key' => 'people6_price',
                    'name' => DB::select()->from('sysconfig')->where("varname='cfg_line_people6_name'")->execute()->get('value')
                )
            );
            $peo_open = DB::select()->from('sysconfig')->where("varname='cfg_line_people_open'")->execute()->get('value');
            $peo_open = explode(',',$peo_open);
            $people_list = array();
            foreach ($peo_open as $v){
                $people_list[] = $peo_arr[$v];
            }
            $people_list[] = array('key'=>'number','name'=>'限购');
            $people_list[] = array('key'=>'roombalance','name'=>'单房差');
            $people_list[] = array('key'=>'propgroup');
        }elseif($type_id==114){
            $people_list = array(
                array(
                    'key' => 'price',
                    'name' => '成人'
                ),
                 array(
                    'key' => 'childprice',
                    'name' => '儿童'
                ),
                 array(
                    'key' => 'number',
                    'name' => '限购'
                )
            );
        }elseif($type_id==2 || $type_id>199){
            $people_list = array(
                array(
                    'key' => 'price',
                    'name' => '价格'
                ),
                array(
                    'key' => 'number',
                    'name' => '限购'
                ),
            );
        }else{
            $people_list = array(
                array(
                    'key' => 'adultprice',
                    'name' => '价格'
                ),
                array(
                    'key' => 'number',
                    'name' => '限购'
                ),
            );
        }

        return $people_list;
    }
}